import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil

class TestAppManagement:
    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/GET_get_chart_installing_stat.yaml'))
    def test_get_chart_installing_stat(self, yaml, get_env_info):
        # 获取某个chart安装后的状态
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/GET_get_specified_helm_release_history_version.yaml'))
    def test_get_specified_helm_release_history_version(self, yaml, get_env_info):
        # 获取release的全部历史版本
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/GET_get_specified_helm_release_info.yaml'))
    def test_get_specified_helm_release_info(self, yaml, get_env_info):
        # 获取指定helm release所有信息
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/GET_get_specified_helm_release_manifest.yaml'))
    def test_get_specified_helm_release_manifest(self, yaml, get_env_info):
        # manifest获取（release的yaml获取）
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/GET_get_specified_helm_release_pod_container.yaml'))
    def test_get_specified_helm_release_pod_container(self, yaml, get_env_info):
        # 获取release内的所有pod和container，提供日志的请求参数
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/GET_get_specified_helm_release_values.yaml'))
    def test_get_specified_helm_release_values(self, yaml, get_env_info):
        # values获取
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/DELETE_delete_helm_release.yaml'))
    def test_delete_helm_release(self, yaml, get_env_info):
        # 删除
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/POST_rollback_helm_release.yaml'))
    def test_rollback_helm_release(self, yaml, get_env_info):
        # 回退
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appManagement/PUT_update_helm_release.yaml'))
    def test_update_helm_release(self, yaml, get_env_info):
        # 升级
        baseUrl = get_env_info
        url = baseUrl + yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']
